Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relayStylePagination honor pageInfo startCursor and endCursor #7224

Merged
merged 5 commits into from
Oct 27, 2020
Merged

relayStylePagination honor pageInfo startCursor and endCursor #7224

merged 5 commits into from
Oct 27, 2020

Conversation

beaucollins
Copy link
Contributor

@beaucollins beaucollins commented Oct 23, 2020

When using relayStylePagination it's possible that the edges are not requested. In my specific case the api I'm integrating with incorrectly returns an empty list of edges in some cases.

The pageInfo however does contain correct endCursor and startCursor values.

The problem with the way that relayStylePagination is implemented is that the startCursor and endCursor will be overridden with an empty string "" instead of honoring the pageInfo sent by the API.

This change includes a test showing the problem (932bcfb) which fails with the state I am seeing:

    expect(received).toEqual(expected) // deep equality

    - Expected  - 2
    + Received  + 2

      Object {
        "edges": Array [],
        "pageInfo": Object {
    -     "endCursor": "xyz",
    +     "endCursor": "",
          "hasNextPage": true,
          "hasPreviousPage": false,
    -     "startCursor": "abc",
    +     "startCursor": "",
        },
      }

The fix in 9ab6311 honors the pageInfo values.

@apollo-cla
Copy link

@beaucollins: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this @beaucollins! I made some tweaks and added more tests, preserving your original improvements.

@benjamn benjamn merged commit 5f87003 into apollographql:main Oct 27, 2020
benjamn added a commit that referenced this pull request Oct 27, 2020
@beaucollins beaucollins deleted the relay-incoming-page-cursors branch October 27, 2020 21:27
benjamn added a commit that referenced this pull request Nov 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants